package com.atguigu.gmall.user.service.impl;

import com.atguigu.gmall.common.util.MD5;
import com.atguigu.gmall.model.user.UserAddress;
import com.atguigu.gmall.model.user.UserInfo;
import com.atguigu.gmall.user.mapper.UserAddressMapper;
import com.atguigu.gmall.user.service.UserInfoService;
import com.atguigu.gmall.user.mapper.UserInfoMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: TODO
 * @Author: Mr.Cao
 * @DateTime: 2021/10/12 18:45
 * BMW F750GS
 **/
@Service
public class UserInfoServiceImpl implements UserInfoService {
    @Autowired
    private UserInfoMapper userInfoMapper;
    @Autowired
    private UserAddressMapper userAddressMapper;
    /**
     * 用户登录:校验用户名密码是否正确
     * */
    @Override
    public UserInfo login(UserInfo userInfo) {

        return userInfoMapper.selectOne(new QueryWrapper<UserInfo>()
          .eq("login_name",userInfo.getLoginName())
                .eq("passwd",MD5.encrypt(userInfo.getPasswd())));
    }
    /**
     * 获取用户的收件人地址集合
     * */
    @Override
    public List<UserAddress> getUserAddressList(Long userId) {
        List<UserAddress> list = userAddressMapper.selectList(new QueryWrapper<UserAddress>().eq("user_id", userId));
        return list;
    }
}
